package alingrad.engine.src.core;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

import alingrad.engine.src.graphics.Renderable;
import alingrad.engine.src.util.RenderQueue;

/**
 * Manager which controls when and what to render.
 * @author alingrad
 *
 */
public class RenderManager {

	/**
	 * The width of the display.
	 */
	public static int WIDTH = 640;

	/**
	 * The height of the display.
	 */
	public static int HEIGHT = 480;

	/**
	 * Queue of all objects that need to be rendered per frame.
	 */
	private static RenderQueue queue;

	/**
	 * Constructs a new render manager with an empty queue.
	 */
	public RenderManager() {
		queue = new RenderQueue();
	}

	/**
	 * Initializes the manager.
	 */
	public static void initialize() {
	}

	/**
	 * Draws all objects within the queue.
	 */
	public static void draw() {
		//clears the screen
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
//		GL11.glClearColor(1f, 1f, 1f, 1f);

		//draws the render queue
		while (!queue.isEmpty()) {
			queue.remove().draw();
		}
		Display.update();
	}

	/**
	 * Adds a Renderable object to the render queue at a specific order.
	 * @param node object to render
	 * @param drawOrder order to render the object.
	 */
	public static void addToQueue(Renderable node, int drawOrder) {
		queue.add(node, drawOrder);
	}

	/**
	 * Adds a Renderable object to the render queue.
	 * @param node object to render.
	 */
	public static void addToQueue(Renderable node) {
		addToQueue(node, 0);
	}
}
